package cn.zzuli.firstapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.RadioGroup;


public class MainActivity extends AppCompatActivity{

    private Button myBtn_one;
    private Button myBtn_two;

    private RadioGroup radioGroup;
    private TextView textView;

    public MainActivity() {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setContentView(R.layout.linear1);//线性布局
        setContentView(R.layout.relative1);//相对布局
        setContentView(R.layout.frame);//帧布局
        setContentView(R.layout.table1);//表格布局
        setContentView(R.layout.absolute1);//绝对布局
        setContentView(R.layout.relative2_textview);//文本
        setContentView(R.layout.linear2_edittext);//编辑框

        /*setContentView(R.layout.relative3_btn);//按钮点击事件
        myBtn_one = (Button)findViewById(R.id.btn_one);
        myBtn_two = (Button)findViewById(R.id.btn_two);
        myBtn_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myBtn_two.setText("按钮2已被点击");
            }
        });*/

        setContentView(R.layout.relative3_btn2);
        /*myBtn_one = (Button)findViewById(R.id.btn_one);//需要实现View.OnClickListener接口
        myBtn_two = (Button)findViewById(R.id.btn_two);
        myBtn_one.setOnClickListener(this);
        myBtn_two.setOnClickListener(this);
        */

        setContentView(R.layout.linear3_radiobutton);
        radioGroup = (RadioGroup)findViewById(R.id.rdg);
        textView = (TextView)findViewById(R.id.rdgtv);
        //利用setOnCheckedChangeListener()为RadioGroup建立监听
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                //判断点击的是哪个RadioButton
                if(checkedId == R.id.rbtn1){
                    textView.setText("您的性别是：男");
                }else{
                    textView.setText("您的性别是：女");
                }
            }
        });

        setContentView(R.layout.relative4_imageview);

    }
    //myBtn_one的点击事件
    /*public void click(View v){
        myBtn_one.setText("按钮1已被点击");
    }*/

    /*public void onClick(View v){
        switch(v.getId()){
            case R.id.btn_one:
                myBtn_one.setText("按钮1已被点击");
                break;
            case R.id.btn_two:
                myBtn_two.setText("按钮2已被点击");
                break;
        }
    }*/
}